<style>
	.webuploader-pick{padding:2px 19px;background:#5cb85c;margin-top: 4px;overflow:unset;}
</style>
<form method="post" action="/oss/?r=resource/doEdit">
    <{include file='../common_params.tpl'}>
    <input type="hidden" name="id" value="<{$info.id}>" />
    <div class="box box-black">
        <div class="box-body">
        	
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 20%;"></col>
                    <col style="width: 80%;"></col>
                </colgroup>
                <input type="hidden" name="type" id="type" value="<{$type}>"/>
                <tr>
                    <th class="th-label">资源文件</th>
                    <td>
                        <div id="filePicker" data-url="<{$url}>" name="file" style="margin-top: 2px;float: left;">上传</div>	
                        <div style="color: red;float: left;margin-top: 7px;margin-left: 10px;" id="file_info"></div>
                        <input type="hidden" name="resoure_url" id="resoure_url" value=""/>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">服务器版本号</th>
                    <td>
                        <input type="number" style="width:60px;" name="s_version" class="form-control inline" placeholder="0" value="<{$info.s_version}>"/>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">apk 地址</th>
                    <td>
                        <input type="text" name="apk" class="form-control inline" placeholder="若无可不填" value="<{$info.apk}>" />
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">平台</th>
                    <td style="padding-top: 15px;">
                    	<{$info.platform}>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">渠道</th>
                    <td style="padding-top: 15px;">
                    	<{foreach from=$channelList item=item key=key}>
                    		<{if $info.channel == $key }>
                    			<{$item}>
                    		<{/if}>                        		
                        <{/foreach}>                    	
                    </td>
                </tr>

            </table>
        </div>

        <div class="box-footer">
            <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
            <button type="submit" name="sub" class="btn btn-default pull-right">保存</button>
        </div>
    </div>
</form>

<script type="text/javascript">
	var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 
	var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
	var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  

	
    $(function(){
    	$('button[name="sub"]').click(function(){
        	var resoure_url = $('input[name="resoure_url"]').val();
        	if(resoure_url == ''){
        		layer.alert('请上传资源文件', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var s_version = $('input[name="s_version"]').val();
        	if(s_version == ''){
        		layer.alert('请输入服务器版本号', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var platform = $('select[name="platform"]').val();
        	if(platform == ''){
        		layer.alert('请选择平台', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var channel = $('select[name="channel"]').val();
        	if(channel == ''){
        		layer.alert('请选择渠道', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	layer.load(2, {
       				 shade: [0.6,'#393D49']
			});

            
        });
    });
</script>




<script>
   var g = $("input[name='g']").val();
   var uploading = null;
   var url = $("#filePicker").attr('data-url');
   $(function(){
	   var uploader = uploadFile({
    	  //server:"?r=goods/importGoods&g="+g,
    	  server:url,
    	  pick:'#filePicker',
    	  timeout: 0,
    	  //fileSizeLimit: 3*1024*1024,
    	  formData: {dir:'temp'},
    	  callback:function(f,file){
    		  layer.close(uploading);
    		  json = eval("("+f+")");
    		  if(json.status==1){
    			  uploader.removeFile(file);
    			  uploader.refresh();
    			  $("#resoure_url").val(json.data);
    		      layer.msg(json.msg, {icon: 1});
    		      $("#file_info").css('color','blue');
    		      $("#file_info").text(json.msg);
    		  }else{
    			  layer.msg('上传失败,出错原因：'+json.msg, {icon: 5});
    			  $("#file_info").text(json.msg);
    		  }
	      },
	      progress:function(rate){	      	
	      	var percent = $('.box-body').find('.progress .progress-bar');
	      	if ( !percent.length ) {
	      		var percent = $('<div class="progress progress-striped active">' +
                '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                '</div>' +
                '</div>').appendTo($('.box-body')).find('.progress-bar');
            }
	      	
	      	var n_rate = parseInt(rate*100)/100;
	      	$('.box-body').find('#file_info').text('上传中: '+ n_rate * 100 + '%');
            percent.css( 'width', rate * 100 + '%' );
	      	//console.log(rate);
	    	//uploading = layer.load(2, {shade: [0.4, '#393D49']});
	      }
      });
   });

function uploadFile(opts){
	var _opts = {};
	_opts = $.extend(_opts,{auto: true,swf: '/public/static/plugin/webuploader/Uploader.swf'},opts);
	var uploader = WebUploader.create(_opts);
	uploader.on('uploadStart', function( file ) {
		uploading = layer.load(2, {shade: [0.4, '#393D49']});
	});
		
//if(isEdge){ //Ed浏览器进度条用这个
//	uploader.on( 'fileQueued', function( file ) {
//		var percent = $('.box-body').find('.progress .progress-bar');
//	      	if ( !percent.length ) {
//	      		var percent = $('<div class="progress progress-striped active">' +
//              '<div class="progress-bar" role="progressbar" style="width: 0%">' +
//              '</div>' +
//              '</div>').appendTo($('.box-body')).find('.progress-bar');
//         }
//		uploader.md5File( file )
//      // 及时显示进度
//      .progress(function(percentage) {
//      	var n_rate = parseInt(percentage*100)/100;
//      	$('.box-body').find('#file_info').text('上传中: '+ n_rate * 100 + '%');
//          percent.css( 'width', percentage * 100 + '%' );
//          //console.log('Percentage:', percentage);
//      })
//      // 完成
//      .then(function(val) {
//          //console.log('md5 result:', val);
//      });
//	});
//}

	uploader.on('uploadSuccess', function( file,response ) {
		//console.log(response);
	    var json = response._raw;
	    if(_opts.callback)_opts.callback(json,file);
	});
	uploader.on('uploadError', function( file,reason ) {
		layer.close(uploading);
		layer.msg('上传失败,原因：'+reason, {icon: 5});
		$("#file_info").text('上传失败,原因：'+reason);		
	});
	
//if(!isEdge){ //其他浏览器进度条用这个
	uploader.on( 'uploadProgress', function( file, percentage ) {
		if(_opts.progress)_opts.progress(percentage);
	});
//}

	uploader.on( 'uploadComplete', function( file ) {
        $( '.box-body' ).find('.progress').fadeOut();
    });
	return uploader;
}

</script>